package me.leiusual.sharing.ui.shop.adapter

import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_shop_bank.*
import me.leiusual.sharing.api.model.Bank

/**
 * author: leiusual
 * create on: 2019-07-29
 * description:
 */
class ShopBankViewHolder(
    override val containerView: View,
    private val clickListener: (Bank) -> Unit,
    private val editListener: (Bank) -> Unit
) : RecyclerView.ViewHolder(containerView), LayoutContainer, View.OnClickListener {

  lateinit var bank: Bank

  init {
    containerView.setOnClickListener(this)
    image_button_edit.setOnClickListener(this)
  }

  fun bind(bank: Bank) {
    this.bank = bank

    text_view_card_owner_name.text = bank.cardOwnerName
    text_view_bank_card_id.text = bank.bankCardId
    text_view_default.isVisible = bank.defaultAccount
    text_view_bank_name.text = bank.bankName
  }

  override fun onClick(v: View?) {
    when (v) {
      containerView -> clickListener(bank)
      image_button_edit -> editListener(bank)
    }
  }
}